function nsePlot( path, numberOfFrames )

T = load(strcat(path, 'ts.txt'));
Tau = load(strcat(path, 'taus.txt'));

global timeStep;
timeStep = max(1, min(floor(length(T)/100), 20));

if nargin < 2
    numberOfFrames = length(T);
end


pTop=load(strcat(path,'processor_topology.txt'));
size=pTop(1)*pTop(2);

topology=zeros(2,size);

for index=1:size
    topology(:,index)=load(strcat(path,'local_topology_',num2str(index-1),'.txt'));
end


plotVelFieldSequence(path, numberOfFrames, T, Tau, topology );

return








function A = loadGlobalMat(path, iterIndex, name, topology,sizeA)

if(nargin==5)
    A=zeros(sizeA);
else
    A = [];
end

[ rows, cols ] = size(topology);
for index=1:cols
    pCoord = topology(:,index)+1;
    filename = strcat(path, name,num2str(iterIndex), '_' , num2str(index-1), '.txt');
    
    temp = load(filename);
   
    [ rows, cols ] = size(temp); 
    A( pCoord(2):(pCoord(2) + rows -1), pCoord(1):(pCoord(1) + cols-1) ) = temp;
    
    
    
end
return




function  plotVelFieldSequence(path, numberOfFrames, T, Tau, topology )

global timeStep;
frameIndices= 1:timeStep:numberOfFrames;
nbrF=length(frameIndices)-1;

clear figure;
name = 'u,v Field';

U = loadGlobalMat(path,1,'u',topology);

[ rows, cols ] = size(U);
sizeA=size(U);
[ X, Y ] = meshgrid(0:1/(cols-1):1, 0:1/(rows-1) :1);


P = zeros(size(U));
P(1, : ) = 1;
P(end, : ) = 1;

for i=1:nbrF
    index = frameIndices(i);
    
    U = loadGlobalMat(path,index,'u',topology,sizeA);
    V = loadGlobalMat(path,index,'v',topology,sizeA);
    P = loadGlobalMat(path,index,'p',topology,sizeA);
    
    
    clear figure;
    caxis([-0.1,0.1]);
    
    
    plotPressure(X,Y,P);
    
    hold on;
    plotVelField(X, Y, U, V);
    setInfo(T, Tau, index, name )
    hold off;
    
    getframe;
    
    
end
return

function plotPressure(X,Y,P)

contourf(X, Y, P, 20);
colormap(autumn);
colorbar;
return

function plotVelField(X, Y, U, V)

scale = 20/length(X);

quiver(X, Y, U*scale, V*scale, 0, 'LineWidth', 1);
alpha(0.5);


return



function  plotSequence(path, fileBaseName, numberOfFrames, T, Tau )

global timeStep;
frameIndices= 1:timeStep:numberOfFrames;
nbrF=length(frameIndices);

clear figure;


A = load(strcat(path, fileBaseName, num2str(frameIndices(1)), '.txt'));
surfc(A);


a = axis;
a(5) = min(min(A));
a(6) =  max(max(A));
axis(a);
colorbar;
setInfo(T, Tau, frameIndices(1), fileBaseName )
set(gca, 'NextPlot', 'replacechildren');

getframe;

for i=2:nbrF
    A = load(strcat(path, fileBaseName, num2str(frameIndices(i)), '.txt'));
    
    surfc(A);
    setInfo(T, Tau, frameIndices(i), fileBaseName );
    
    getframe;
    
    
end
return

function setInfo(T, Tau, i, fileBaseName )
title(strcat(fileBaseName, '(t=', num2str(T(i)) ,'), n=', num2str(i), '/', num2str(length(T)), ', with tau=' , num2str(Tau(i))));
xlabel('x');
ylabel('y');
zlabel(fileBaseName);

return